<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FormData</title>
</head>
<body>
    <form id="form">
        <input type="text" name="username">
        <input type="password" name="password">
        <input type="button" id="btn" value="提交">
    </form>

    <script>
        var btn = document.getElementById('btn')
        btn.onclick = function () {
            var fd = new FormData(document.getElementById('form'))
            var xhr = new XMLHttpRequest()
            xhr.open('post','http://localhost:3000/formdata')
            xhr.send(fd)
            xhr.onload = function () {
                if (xhr.status == 200){
                	console.log(xhr.responseText)
                }
            }
        }
    </script>
</body>
</html>